package com.king.reference.weak;

import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;

import com.king.reference.CheckRefQueue;
import com.king.reference.MyObject;

/**
 * @author taomk
 * @version 1.0
 * @since 15-1-27 下午10:47
 */
public class WeakReferenceTest {

	public static void main(String [] args) {
		MyObject obj = new MyObject();
		ReferenceQueue<MyObject> weakQueue = new ReferenceQueue<>();

		WeakReference<MyObject> weakObjRef = new WeakReference<>(obj, weakQueue);
		new CheckRefQueue(weakQueue).start();
		obj = null;
		System.out.println("Before GC: Weak Get= " + weakObjRef.get());
		System.gc();
		System.out.println("After new byte[]: Soft Get= " + weakObjRef.get());
	}
}
